package com.visikard.response;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.visikard.application.Constant;
import com.visikard.item.MerchantAccountObj;

public class MerchantLoginResponse extends BaseResponse {

	public static final int ERROR_WRONG_USERNAME_PASSWORD = BaseResponse.USER_DEFINED_ERROR;

	private MerchantAccountObj account;

	public MerchantLoginResponse() {
		super();
	}

	public MerchantAccountObj getAccount() {
		return account;
	}

	public void setAccount(MerchantAccountObj account) {
		this.account = account;
	}

	@Override
	public void extractDataFromServer(String response) throws JSONException {
		super.extractDataFromServer(response);

		if (errorCode == SUCCESS) {
			JSONObject jDataObj = getDataJObject(response);
			account = new MerchantAccountObj(jDataObj);
		}
		else if (errorCode != INVALID_RESPONSE) {
			// In this case the username and password are wrong
			Log.e(Constant.LOG_TAG, "loginApp: " + "Wrong username and password!!!");
			errorCode = MerchantLoginResponse.ERROR_WRONG_USERNAME_PASSWORD;
			errorMsg = "Wrong username and password!!!";
		}
	}

}
